package com.foreveross.fetl.core.domain.freight.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.foreveross.fetl.common.jpa.EntityHibernateRepository;
import com.foreveross.fetl.core.domain.freight.CrawlTaskTemplateEntity;
import com.foreveross.fetl.core.domain.freight.repository.ICrawlTaskTemplateRepository;
@Repository("crawlTaskTemplateRepository")
public class CrawlTaskTemplateRepositoryImpl extends EntityHibernateRepository implements ICrawlTaskTemplateRepository{
	public List<CrawlTaskTemplateEntity> getCrawlTaskTemplateList(String name) {
		StringBuffer jpql =new StringBuffer("select crawlTaskTemplate from CrawlTaskTemplateEntity crawlTaskTemplate where 1=1");
		List<Object> conditionVals = new ArrayList<Object>();
		if(name!=null){
			jpql.append(" and crawlTaskTemplate.grabChannel =? ");
			conditionVals.add(name);
		}
		return super.queryResult(jpql.toString(), conditionVals.toArray());
	}

	@Override
	public CrawlTaskTemplateEntity findByCondition(String attachHbaseKey,String fromCity,String toCity) {
		StringBuffer jpql =new StringBuffer("select crawlTaskTemplate from CrawlTaskTemplateEntity crawlTaskTemplate where 1=1");
		List<Object> conditionVals = new ArrayList<Object>();
		jpql.append(" and crawlTaskTemplate.attachHbaseKey =? ");
		conditionVals.add(attachHbaseKey);
		jpql.append(" and crawlTaskTemplate.fromCity =? ");
		conditionVals.add(fromCity);
		jpql.append(" and crawlTaskTemplate.toCity =? ");
		conditionVals.add(toCity);
		return (CrawlTaskTemplateEntity) super.queryResult(jpql.toString(), conditionVals.toArray()).get(0);
	}
}
